import 'package:creatures_world/data/animal_data_tool.dart';
import 'package:creatures_world/framework/ext_dart/map_ext.dart';
import 'package:creatures_world/pages/base/base_controller.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';

class FuncController extends BaseController{



  TextEditingController searchTextEditingController =TextEditingController();
  var matchedList=[].obs;

  @override
  void onInit() {
    super.onInit();
    searchTextEditingController.addListener((){
      if(searchTextEditingController.text.isEmpty){
        matchedList.value=[];
      }
    });

  }

  static List<dynamic>  onSearchInput(SearchParams sp){

    List<dynamic> matchedList =[];
    if(sp.text.isNotEmpty && sp.text.length>=2){
      String input2=sp.text.substring(0,2);
      if(sp.animalMap.containsKey(input2)){
        String lowerTextInput=sp.text.toLowerCase();
        List<Map<String,dynamic>>? itemList=sp.animalMap[input2]?.cast<Map<String, dynamic>>();
        if(itemList?.isNotEmpty==true){
          for(Map<String,dynamic> item in itemList!){
            String name=item.nn2("name");
            if(name.contains(lowerTextInput)){
              matchedList.add(item);
              debugPrint("match name--> ${name}");
            }
          }
        }
      }
    }
    debugPrint("------------------------------");
    return matchedList;
  }



}